package DynamicProgramming.Medium;

public class LC0198 {
    public static int rob(int[] nums) {
        int nHouses = nums.length;
        int[] dp = new int[nHouses + 1]; // 偷完第i家后，最多可获得的收益
        dp[0] = 0;
        dp[1] = nums[0];
        for (int i = 2; i <= nHouses; i++) {
            dp[i] = Math.max(nums[i - 1] + dp[i - 2], dp[i - 1]);
        }

        return dp[nHouses];
    }

    public static void main(String[] args) {
        int[] nums = new int[]{1, 2, 3, 1};
        System.out.println(rob(nums));
    }
}
